<template>
  <div class="h100" @click="closeSetting">
    <!-- 非全屏 start -->
    <div class="no-full" v-show="!isFullscreen">
      <transition name="fade">
        <small class="header-next clearfix" v-if="showWarningInfo && !obAccessKey">{{$t('dashboard.no_hash_info')}}<span class="pointer p-span" @click="toSetWarning">{{$t('dashboard.no_hash_btn')}}>></span><i @click="showWarningInfo = false;" class="fr icon iconfont icon-close pointer"></i></small>
      </transition>
      <div class="w">
        <!-- 面包屑 start -->
        <div class="dashboard-title clearfix">
          <Breadcrumb class="fl" :breadcrumbs="breadcrumbs" />
          <button @click="toFullScreen" class="fr full-btn">{{$t('dashboard.full_screen')}}</button>
        </div>
        <!-- 面包屑 end -->
        <!-- 顶部 start -->
        <div class="panel-top">
          <div class="item-title clearfix">
            <div class="name fl">{{$t('dashboard.real_data')}}</div>
            <div class="button-box fr">
              <button :class="{active:showData}" @click="showData = true;">{{$t('dashboard.show')}}</button>
              <button :class="{active:!showData}" @click="showData = false;">{{$t('dashboard.hide')}}</button>
            </div>
          </div>
          <div class="item-content">
            <div class="item">
              <div class="item-top">
                <spinner v-if="loading.subaccountStats_init_loading" />
                <template v-else>
                  <cu class="val" v-show="showData" :val="shares_15m | num" :decimals="2"></cu>
                  <span class="val" v-show="!showData">**********</span>
                  <span class="unit">{{shares_unit}}H/S</span>
                </template>
              </div>
              <div class="item-bottom">
                <span class="name">{{$t('dashboard.real_force')}}</span>
              </div>
            </div>
            <div class="item">
              <div class="item-top">
                <spinner v-if="loading.subaccountStats_init_loading" />
                <template v-else>
                  <cu class="val" v-show="showData" :val="workers_active | num" :decimals="0"></cu>
                  <span class="val" v-show="!showData">**********</span>
                  <span class="unit">{{$t('unit.station')}}</span>
                </template>
              </div>
              <div class="item-bottom">
                <span class="name">{{$t('dashboard.workers_active')}}</span>
              </div>
            </div>
            <div class="item">
              <div class="item-top">
                <spinner v-if="loading.paymentInfo_init_loading" />
                <template v-else>
                  <cu class="val" v-show="showData" :val="paymentInfoData.per | num" :decimals="8"></cu>
                  <span class="val" v-show="!showData">**********</span>
                  <span class="unit">BTC</span>
                </template>
              </div>
              <div class="item-bottom">
                <span class="name">{{$t('dashboard.paymentInfoData_per')}}</span>
              </div>
            </div>
          </div>
        </div>
        <!-- 顶部 end -->
        <!-- 算力 start -->
        <div class="panel-item clearfix">
          <div class="item fl">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('home.force')}}</span>
            </div>
            <div class="item-content">
              <table class="item-table suanli-table">
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.minutes_15')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.subaccountStats_init_loading" />
                      <template v-else>
                        <cu class="val" :val="shares_15m | num" :decimals="2"></cu>
                        <span class="unit">{{shares_unit}}H/S</span>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.one_houer')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.subaccountStats_init_loading" />
                      <template v-else>
                        <cu class="val" :val="shares_1h | num" :decimals="2"></cu>
                        <span class="unit">{{shares_unit}}H/S</span>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.hour_24')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.subaccountStats_init_loading" />
                      <template v-else>
                        <cu class="val" :val="shares_24h | num" :decimals="2"></cu>
                        <span class="unit">{{shares_unit}}H/S</span>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr v-show="!suanli_is_setting">
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.hash_rate1')}}</span>
                      <button v-if="!obAccessKey" class="setting" @click.stop="suanli_is_setting=true;set_asset.hash_rate=asset.share;set_asset.unit=asset.unit">{{$t('dashboard.set')}}</button>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.get_subaccount_asset_loading" />
                      <template v-else>
                        <cu class="val" :val="asset.share | num" :decimals="2"></cu>
                        <span class="unit">{{asset.unit}}H/S</span>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr v-show="suanli_is_setting">
                  <td colspan="2" class="setting-td">
                    <div class="td-cell input-td-cell" @click.stop>
                      <div class="input-box clearfix">
                        <input class="fl input-box_input" v-model="set_asset.hash_rate" type="text" :disabled="loading.set_subaccount_asset_share_loading" :placeholder="$t('dashboard.hash_rate_input')"
                        @keyup.enter="setSubaccountAsset(2)">
                        <el-select :disabled="loading.set_subaccount_asset_share_loading" class="dashboard-select fl" v-model="set_asset.unit" :placeholder="$t('dashboard.selector')">
                          <el-option v-for="(v,k) in suanli_unit_list" :key="k" :label="k" :value="k">
                          </el-option>
                        </el-select>
                        <button :disabled="loading.set_subaccount_asset_share_loading" class="fr" @click="setSubaccountAsset(2)">
                          <template v-if="!loading.set_subaccount_asset_share_loading">{{$t('btn.save')}}</template>
                          <i v-else class="el-icon-loading"></i>
                        </button>
                      </div>
                    </div>
                  </td>
                </tr>
              </table>
            </div>
          </div>
          <div class="item fr">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.calculation_curve')}}</span>
              <div class="button-box fr" v-if="!noMill || hasIncome">
                <button :class="{active:suanLi_dimension==='1h'}" :disabled="suanLi_dimension==='1h'||loading.subaccountHistory_init_loading" @click="suanLi_dimension = '1h';loading.subaccountHistory_init_loading=true;">{{$t('unit.hour')}}</button>
                <button :class="{active:suanLi_dimension==='1d'}" :disabled="suanLi_dimension==='1d'||loading.subaccountHistory_init_loading" @click="suanLi_dimension = '1d';loading.subaccountHistory_init_loading=true;">{{$t('unit.day')}}</button>
              </div>
            </div>
            <div class="item-content" v-loading="loading.subaccountHistory_init_loading" :element-loading-text="$t('unit.loading')">
              <echarts class="dashboard-echarts" ref="suanli_noFull_echarts" :option="suanLiEchartsOption" v-if="!noMill || hasIncome" />
              <div v-else class="noData">
                <p>{{$t('dashboard.no_mill')}}</p>
                <a target="_blank" :href="helpHref">{{$t('dashboard.add_mill')}} >></a>
              </div>
            </div>
          </div>
        </div>
        <!-- 算力 end -->
        <!-- 矿机 start -->
        <div class="panel-item clearfix">
          <div class="item fl">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.minging_machine')}}</span>
              <router-link class="link fr" to="/pools/mill">{{$t('dashboard.minging_machine_detail')}}</router-link>
            </div>
            <div class="item-content">
              <table class="item-table kuangji-table">
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.active')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.subaccountStats_init_loading" />
                      <cu v-else class="val" :val="workers_active | num" :decimals="0"></cu>
                    </div>
                  </td>
                </tr>
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.inactive')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.subaccountStats_init_loading" />
                      <cu v-else class="val" :val="workers_inactive | num" :decimals="0"></cu>
                    </div>
                  </td>
                </tr>
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.invalid')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.subaccountStats_init_loading" />
                      <cu v-else class="val" :val="workers_dead | num" :decimals="0"></cu>
                    </div>
                  </td>
                </tr>
                <tr v-show="!kuangji_is_setting">
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.mining_machine_assets')}}</span>
                      <button v-if="!obAccessKey" class="setting" @click.stop="kuangji_is_setting=true;set_asset.worker_num=asset.worker_num;">{{$t('dashboard.set')}}</button>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.get_subaccount_asset_loading" />
                      <template v-else>
                        <cu class="val" :val="asset.worker_num | num" :decimals="0"></cu>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr v-show="kuangji_is_setting">
                  <td colspan="2" class="setting-td">
                    <div class="td-cell input-td-cell" @click.stop>
                      <div class="input-box clearfix">
                        <input :disabled="loading.set_subaccount_asset_worker_loading" class="fl kuangji_input input-box_input" v-model="set_asset.worker_num" type="text" :placeholder="$t('dashboard.mining_info')" @keyup.enter="setSubaccountAsset(1)">
                        <button :disabled="loading.set_subaccount_asset_worker_loading" class="fr" @click="setSubaccountAsset(1)">
                          <template v-if="!loading.set_subaccount_asset_worker_loading">{{$t('btn.save')}}</template>
                          <i v-else class="el-icon-loading"></i>
                        </button>
                      </div>
                    </div>
                  </td>
                </tr>
              </table>
            </div>
          </div>
          <div class="item fr">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.minging_curve')}}</span>
              <div class="button-box fr" v-if="!noMill || hasIncome">
                <button :class="{active:kuangji_dimension==='1h'}" :disabled="kuangji_dimension==='1h'||loading.getWorkerStas_init_loading" @click="kuangji_dimension = '1h';loading.getWorkerStas_init_loading=true;">{{$t('unit.hour')}}</button>
                <button :class="{active:kuangji_dimension==='1d'}" :disabled="kuangji_dimension==='1d'||loading.getWorkerStas_init_loading" @click="kuangji_dimension = '1d';loading.getWorkerStas_init_loading=true;">{{$t('unit.day')}}</button>
              </div>
            </div>
            <div class="item-content" v-loading="loading.getWorkerStas_init_loading" :element-loading-text="$t('unit.loading')">
              <echarts class="dashboard-echarts" ref="kuangji_noFull_echarts" :option="kuangJiEchartsOption" v-if="!noMill || hasIncome" />
              <div v-else class="noData">
                <p>{{$t('dashboard.no_mill2')}}</p>
                <a target="_blank" :href="helpHref">{{$t('dashboard.add_mill')}} >></a>
              </div>
            </div>
          </div>
        </div>
        <!-- 矿机 end -->
        <!-- 收益 start -->
        <div class="panel-item clearfix">
          <div class="item fl">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.income')}}</span>
              <router-link class="link fr" to="/pools/income">{{$t('dashboard.income_detail')}}</router-link>
            </div>
            <div class="item-content">
              <table class="item-table shouyi-table">
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.total_income')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.paymentInfo_init_loading" />
                      <template v-else>
                        <cu class="val" :val="paymentInfoData.total_earn | num" :decimals="8"></cu>
                        <span class="unit">BTC</span>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.yesterdayearn')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.paymentInfo_init_loading" />
                      <template v-else>
                        <cu class="val" :val="paymentInfoData.yesterdayearn | num" :decimals="8"></cu>
                        <span class="unit">BTC</span>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.pay_amount')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.paymentInfo_init_loading" />
                      <template v-else>
                        <cu class="val" :val="paymentInfoData.pay_amount | num" :decimals="8"></cu>
                        <span class="unit">BTC</span>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.earn')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner v-if="loading.paymentInfo_init_loading" />
                      <template v-else>
                        <cu class="val" :val="paymentInfoData.earn | num" :decimals="8"></cu>
                        <span class="unit">BTC</span>
                      </template>
                    </div>
                  </td>
                </tr>
              </table>
            </div>
          </div>
          <div class="item fr">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.income_curve')}}</span>
              <div class="button-box fr" v-if="!noMill || hasIncome">
                <button :class="{active:paymentHistoryLimit===7}" :disabled="paymentHistoryLimit===7||loading.paymentHistory_init_loading" @click="paymentHistoryLimit = 7;loading.paymentHistory_init_loading = true;">{{$t('unit.week')}}</button>
                <button :class="{active:paymentHistoryLimit===30}" :disabled="paymentHistoryLimit===30||loading.paymentHistory_init_loading" @click="paymentHistoryLimit = 30;
                loading.paymentHistory_init_loading = true;">{{$t('unit.month')}}</button>
              </div>
            </div>
            <div class="item-content" v-loading="loading.paymentHistory_init_loading" :element-loading-text="$t('unit.loading')">
              <echarts class="dashboard-echarts" ref="shouyi-echarts" :option="shouyiOption" v-if="!noMill || hasIncome" />
              <div v-else class="noData">
                <p>{{$t('dashboard.no_mill3')}}</p>
                <a target="_blank" :href="helpHref">{{$t('dashboard.add_mill')}} >></a>
              </div>
            </div>
          </div>
        </div>
        <!-- 收益 end -->
        <!-- 底部列表 start -->
        <div class="panel-bottom clearfix">
          <div v-loading="loading.active_workers_loading" :element-loading-text="$t('unit.loading')" class="item fl">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.new_dynamic')}}</span>
            </div>
            <div class="item-content">
              <table class="item-table">
                <thead>
                  <tr>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.time')}}</span>
                      </div>
                    </th>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.minging_machine')}}</span>
                      </div>
                    </th>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.now_rate')}}</span>
                      </div>
                    </th>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="(v,k) in active_workers" :key="k">
                    <td>
                      <div class="td-cell">
                        <span>{{v.share_time}}</span>
                      </div>
                    </td>
                    <td>
                      <div class="td-cell">
                        <router-link :to="'/pools/mill/'+v.worker_id+'|'+v.node">{{v.worker_name}}</router-link>
                      </div>
                    </td>
                    <td>
                      <div class="td-cell">
                        <span>{{v.shares_15m}}&ensp;{{v.shares_unit}}</span>
                      </div>
                    </td>
                  </tr>
                  <tr v-if="!active_workers.length">
                    <td colspan="3">
                      <div class="td-cell">
                        <p>{{$t('unit.no_data')}}</p>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
          <div v-loading="loading.inActive_workers_loading" :element-loading-text="$t('unit.loading')" class="item fr">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.no_new_dynamic')}}</span>
            </div>
            <div class="item-content">
              <table class="item-table">
                <thead>
                  <tr>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.last_commit_time')}}</span>
                      </div>
                    </th>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.minging_machine')}}</span>
                      </div>
                    </th>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.now_rate')}}</span>
                      </div>
                    </th>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="(v,k) in inActive_workers" :key="k">
                    <td>
                      <div class="td-cell">
                        <span>{{v.share_time}}</span>
                      </div>
                    </td>
                    <td>
                      <div class="td-cell">
                        <router-link :to="'/pools/mill/'+v.worker_id+'|'+v.node">{{v.worker_name}}</router-link>
                      </div>
                    </td>
                    <td>
                      <div class="td-cell">
                        <span>{{v.shares_15m}}&ensp;{{v.shares_unit}}</span>
                      </div>
                    </td>
                  </tr>
                  <tr v-if="!inActive_workers.length">
                    <td colspan="3">
                      <div class="td-cell">
                        <p>{{$t('unit.no_data')}}</p>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
        </div>
        <!-- 底部列表 end -->
      </div>
    </div>
    <!-- 非全屏 end -->
    <!-- 全屏 start -->
    <div class="full" v-show="isFullscreen">
      <div class="full-header">
        <!-- <template v-if="!obAccessKey">
          <span class="nav-split">/</span>
          <a class="change_account" @mouseover="showSubAccount=true;" @mouseleave="showSubAccount=false;" href="javascript:;">
            <span>{{$t('dashboard.turn_subaccount')}}</span>
            <sub-account v-if="showSubAccount" :className="'dashboard-account'" />
          </a>
        </template> -->
        <span class="nav-split">/</span>
        <a href="javascript:;" @click="exitFullScreen">{{$t('dashboard.close_screen')}}</a>
        <span class="nav-split">/</span>
      </div>
      <div class="full-content">
        <!-- 算力 start -->
        <div class="panel-item">
          <div class="item">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.rate')}}</span>
            </div>
            <div class="item-content">
              <table class="item-table suanli-table">
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.minutes_15')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner :size="spinner_size" color="#c0a465" v-if="loading.subaccountStats_init_loading" />
                      <template v-else>
                        <cu class="val" :val="shares_15m | num" :decimals="2"></cu>
                        <span class="unit">{{shares_unit}}H/S</span>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.one_houer')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner :size="spinner_size" color="#c0a465" v-if="loading.subaccountStats_init_loading" />
                      <template v-else>
                        <cu class="val" :val="shares_1h | num" :decimals="2"></cu>
                        <span class="unit">{{shares_unit}}H/S</span>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.hour_24')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner :size="spinner_size" color="#c0a465" v-if="loading.subaccountStats_init_loading" />
                      <template v-else>
                        <cu class="val" :val="shares_24h | num" :decimals="2"></cu>
                        <span class="unit">{{shares_unit}}H/S</span>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr v-show="!suanli_is_setting">
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.hash_rate1')}}</span>
                      <button v-if="!obAccessKey" class="setting" @click.stop="suanli_is_setting=true;set_asset.hash_rate=asset.share;set_asset.unit=asset.unit">{{$t('dashboard.set')}}</button>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner :size="spinner_size" color="#c0a465" v-if="loading.get_subaccount_asset_loading" />
                      <template v-else>
                        <cu class="val" :val="asset.share | num" :decimals="2"></cu>
                        <span class="unit">{{asset.unit}}H/S</span>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr v-show="suanli_is_setting">
                  <td colspan="2" class="setting-td">
                    <div class="td-cell input-td-cell" @click.stop>
                      <div class="input-box clearfix">
                        <input :disabled="loading.set_subaccount_asset_share_loading" class="fl input-box_input" v-model="set_asset.hash_rate" type="text" :placeholder="$t('dashboard.hash_rate_input')"
                        @keyup.enter="setSubaccountAsset(2)">
                        <el-select :disabled="loading.set_subaccount_asset_share_loading" class="dashboard-select fl" v-model="set_asset.unit" :placeholder="$t('dashboard.selector')">
                          <el-option v-for="(v,k) in suanli_unit_list" :key="k" :label="k" :value="k">
                          </el-option>
                        </el-select>
                        <button :disabled="loading.set_subaccount_asset_share_loading" class="fr" @click="setSubaccountAsset(2)">
                          <template v-if="!loading.set_subaccount_asset_share_loading">{{$t('btn.save')}}</template>
                          <i v-else class="el-icon-loading"></i>
                        </button>
                      </div>
                    </div>
                  </td>
                </tr>
              </table>
            </div>
          </div>
          <div class="item">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.calculation_curve')}}</span>
              <div class="button-box fr" v-if="!noMill || hasIncome">
                <button :class="{active:suanLi_dimension==='1h'}" :disabled="suanLi_dimension==='1h'||loading.subaccountHistory_init_loading" @click="suanLi_dimension = '1h';loading.subaccountHistory_init_loading=true;">{{$t('unit.hour')}}</button>
                <button :class="{active:suanLi_dimension==='1d'}" :disabled="suanLi_dimension==='1d'||loading.subaccountHistory_init_loading" @click="suanLi_dimension = '1d';loading.subaccountHistory_init_loading=true;">{{$t('unit.day')}}</button>
              </div>
            </div>
            <div class="item-content" v-loading="loading.subaccountHistory_init_loading" :element-loading-text="$t('unit.loading')" element-loading-background="rgba(0, 0, 0, 0.8)">
              <echarts ref="suanli_full_echarts" :option="suanLiFullEchartsOption" v-if="!noMill || hasIncome" />
              <div v-else class="noData">
                <p>{{$t('dashboard.no_mill')}}</p>
                <a target="_blank" :href="helpHref">{{$t('dashboard.add_mill')}} >></a>
              </div>
            </div>
          </div>
          <div v-loading="loading.active_workers_loading" :element-loading-text="$t('unit.loading')" element-loading-background="rgba(0, 0, 0, 0.8)" class="item">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.new_dynamic')}}</span>
            </div>
            <div class="item-content">
              <table class="item-table">
                <thead>
                  <tr>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.time')}}</span>
                      </div>
                    </th>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.minging_machine')}}</span>
                      </div>
                    </th>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.now_rate')}}</span>
                      </div>
                    </th>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="(v,k) in active_workers" :key="k">
                    <td>
                      <div class="td-cell">
                        <span>{{v.share_time}}</span>
                      </div>
                    </td>
                    <td>
                      <div class="td-cell">
                        <router-link :to="'/pools/mill/'+v.worker_id+'|'+v.node">{{v.worker_name}}</router-link>
                      </div>
                    </td>
                    <td>
                      <div class="td-cell">
                        <span>{{v.shares_15m}}&ensp;{{v.shares_unit}}</span>
                      </div>
                    </td>
                  </tr>
                  <tr v-if="!active_workers.length">
                    <td colspan="3">
                      <div class="td-cell">
                        <p>{{$t('unit.no_data')}}</p>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
        </div>
        <!-- 算力 end -->
        <!-- 矿机 start -->
        <div class="panel-item">
          <div class="item">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.minging_machine')}}</span>
              <router-link class="link fr" to="/pools/mill">{{$t('dashboard.minging_machine_detail')}}</router-link>
            </div>
            <div class="item-content">
              <table class="item-table kuangji-table">
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.active')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner :size="spinner_size" color="#c0a465" v-if="loading.subaccountStats_init_loading" />
                      <cu v-else class="val" :val="workers_active | num" :decimals="0"></cu>
                    </div>
                  </td>
                </tr>
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.inactive')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner :size="spinner_size" color="#c0a465" v-if="loading.subaccountStats_init_loading" />
                      <cu v-else class="val" :val="workers_inactive | num" :decimals="0"></cu>
                    </div>
                  </td>
                </tr>
                <tr>
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.invalid')}}</span>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner :size="spinner_size" color="#c0a465" v-if="loading.subaccountStats_init_loading" />
                      <cu v-else class="val" :val="workers_dead | num" :decimals="0"></cu>
                    </div>
                  </td>
                </tr>
                <tr v-show="!kuangji_is_setting">
                  <th>
                    <div class="td-cell">
                      <span>{{$t('dashboard.mining_machine_assets')}}</span>
                      <button v-if="!obAccessKey" class="setting" @click.stop="kuangji_is_setting=true;set_asset.worker_num=asset.worker_num;">{{$t('dashboard.set')}}</button>
                    </div>
                  </th>
                  <td>
                    <div class="td-cell">
                      <spinner :size="spinner_size" color="#c0a465" v-if="loading.get_subaccount_asset_loading" />
                      <template v-else>
                        <cu class="val" :val="asset.worker_num | num" :decimals="0"></cu>
                      </template>
                    </div>
                  </td>
                </tr>
                <tr v-show="kuangji_is_setting">
                  <td colspan="2" class="setting-td">
                    <div class="td-cell input-td-cell" @click.stop>
                      <div class="input-box clearfix">
                        <input :disabled="loading.set_subaccount_asset_worker_loading" class="fl kuangji_input input-box_input" v-model="set_asset.worker_num" type="text" :placeholder="$t('dashboard.mining_info')"
                        @keyup.enter="setSubaccountAsset(1)">
                        <button :disabled="loading.set_subaccount_asset_worker_loading" class="fr" @click="setSubaccountAsset(1)">
                          <template v-if="!loading.set_subaccount_asset_worker_loading">{{$t('btn.save')}}</template>
                          <i v-else class="el-icon-loading"></i>
                        </button>
                      </div>
                    </div>
                  </td>
                </tr>
              </table>
            </div>
          </div>
          <div class="item">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.minging_curve')}}</span>
              <div class="button-box fr" v-if="!noMill || hasIncome">
                <button :class="{active:kuangji_dimension==='1h'}" :disabled="kuangji_dimension==='1h'||loading.getWorkerStas_init_loading" @click="kuangji_dimension = '1h';loading.getWorkerStas_init_loading=true;">{{$t('unit.hour')}}</button>
                <button :class="{active:kuangji_dimension==='1d'}" :disabled="kuangji_dimension==='1d'||loading.getWorkerStas_init_loading" @click="kuangji_dimension = '1d';loading.getWorkerStas_init_loading=true;">{{$t('unit.day')}}</button>
              </div>
            </div>
            <div class="item-content" v-loading="loading.getWorkerStas_init_loading" :element-loading-text="$t('unit.loading')" element-loading-background="rgba(0, 0, 0, 0.8)">
              <echarts ref="kuangji_full_echarts" :option="kuangJiFullEchartsOption" v-if="!noMill || hasIncome" />
              <div v-else class="noData">
                <p>{{$t('dashboard.no_mill2')}}</p>
                <a target="_blank" :href="helpHref">{{$t('dashboard.add_mill')}} >></a>
              </div>
            </div>
          </div>
          <div v-loading="loading.inActive_workers_loading" :element-loading-text="$t('unit.loading')" element-loading-background="rgba(0, 0, 0, 0.8)" class="item">
            <div class="item-title clearfix">
              <span class="name fl">{{$t('dashboard.no_new_dynamic')}}</span>
            </div>
            <div class="item-content">
              <table class="item-table">
                <thead>
                  <tr>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.time')}}</span>
                      </div>
                    </th>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.minging_machine')}}</span>
                      </div>
                    </th>
                    <th>
                      <div class="td-cell">
                        <span>{{$t('dashboard.now_rate')}}</span>
                      </div>
                    </th>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="(v,k) in inActive_workers" :key="k">
                    <td>
                      <div class="td-cell">
                        <span>{{v.share_time}}</span>
                      </div>
                    </td>
                    <td>
                      <div class="td-cell">
                        <router-link :to="'/pools/mill/'+v.worker_id+'|'+v.node">{{v.worker_name}}</router-link>
                      </div>
                    </td>
                    <td>
                      <div class="td-cell">
                        <span>{{v.shares_15m}}&ensp;{{v.shares_unit}}</span>
                      </div>
                    </td>
                  </tr>
                  <tr v-if="!inActive_workers.length">
                    <td colspan="3">
                      <div class="td-cell">
                        <p>{{$t('unit.no_data')}}</p>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
        </div>
        <!-- 矿机 end -->
      </div>
    </div>
    <!-- 全屏 end -->
  </div>
</template>
<script>
import {
  paymentInfo,
  getHistoryProfit,
  workerList,
  subaccountStats,
  subaccountHistory,
  getSubaccountAsset,
  setSubaccountAsset,
  getWorkerStas,
  getWarning,
} from '@/api';
import echarts from '@/components/Echarts';
import Breadcrumb from '@/components/Breadcrumb';
import Cu from '@/components/CountUp';
import Spinner from '@/components/Spinner';
import screenfull from 'screenfull';
import moment from 'moment';
import { mapGetters, mapMutations } from 'vuex';
import { suanLiEchartsOption, suanLiFullEchartsOption } from './common/suanLiEchartsOption';
import { kuangJiEchartsOption, kuangJiFullEchartsOption } from './common/kuangJiEchartsOption';
import shouyiOption from './common/shouyiOption';

export default {
  name: 'btc',
  components: {
    echarts,
    Breadcrumb,
    Cu,
    Spinner,
  },
  data() {
    return {
      noMill: false,
      spinner_size: '.03125rem',
      showData: true,
      loading: {
        get_subaccount_asset_loading: false,

        set_subaccount_asset_share_loading: false,
        set_subaccount_asset_worker_loading: false,


        active_workers_loading: false,
        inActive_workers_loading: false,

        paymentHistory_init_loading: true,
        paymentHistory_loading: false,

        paymentInfo_init_loading: true,
        paymentInfo_loading: false,

        getWorkerStas_init_loading: true,
        getWorkerStas_loading: false,

        subaccountStats_init_loading: true,
        subaccountStats_loading: false,
        subaccountHistory_init_loading: true,
        subaccountHistory_loading: false,
      },
      timer: null,
      breadcrumbs: [
        {
          path: '/',
          titleKey: 'router.home',
        },
        {
          path: '/pools/dashboard',
          titleKey: 'router.dashboard',
        },
      ],
      shares_15m: 0,
      shares_1h: 0,
      shares_24h: 0,
      workers_active: 0,
      workers_dead: 0,
      workers_inactive: 0,
      shares_unit: '',
      asset: {
        unit: 'T',
        share: 0,
        worker_num: 0,
      },
      set_asset: {
        hash_rate: 0,
        unit: '',
        worker_num: 0,
      },
      suanli_is_setting: false,
      suanli_unit_list: {
        G: 1,
        T: 10 ** 3,
        P: 10 ** 6,
        E: 10 ** 9,
      },
      kuangji_is_setting: false,
      paymentInfoData: {
        earn: '0', // 账户余额
        pay_amount: '0', // 已支付
        per: '0', // 今日预估
        total_earn: '0', // 总收入
        yesterdayearn: '0', // 昨日收益
      },
      paymentHistoryLimit: 30,
      suanLi_dimension: '1h',
      kuangji_dimension: '1h',
      subaccount_history_time: [],
      subaccount_history_share: [],
      subaccount_history_rejectRate: [],
      subaccount_history_unit: '',
      get_worker_stas_data: {
        active: [],
        inactive: [],
        time: [],
        worker_all: [],
      },
      // get_worker_active_time: [],
      // get_worker_active_worker_num: [],
      suanLiEchartsOption: JSON.parse(JSON.stringify(suanLiEchartsOption)),
      suanLiFullEchartsOption: JSON.parse(JSON.stringify(suanLiFullEchartsOption)),
      shouyiOption: JSON.parse(JSON.stringify(shouyiOption)),
      kuangJiEchartsOption: JSON.parse(JSON.stringify(kuangJiEchartsOption)),
      kuangJiFullEchartsOption: JSON.parse(JSON.stringify(kuangJiFullEchartsOption)),
      active_workers: [],
      inActive_workers: [],
      getWarning_init: true,
      showWarningInfo: false,
    };
  },
  computed: {
    ...mapGetters(['subCuid', 'id', 'obAccessKey', 'language']),
    preHelpHref() {
      return `https://support.dpool.top/hc/${this.language === 'zh' ? 'zh-cn' : 'en-us'}`;
    },
    helpHref() {
      return `${this.preHelpHref}/articles/360015486632`;
    },
    hasIncome() {
      return parseFloat(this.paymentInfoData.total_earn) || 0;
    },
    isFullscreen: {
      get() {
        return this.$store.getters.isFullscreen;
      },
      set(val) {
        this.SET_IS_FULLSCREEN(val);
      },
    },
    subaccount_history_current_share() {
      return this.subaccount_history_share.map((v) => {
        const share = (v * this.suanli_unit_list[this.subaccount_history_unit]) / this.suanli_unit_list[this.asset.unit];
        return (Math.floor(share * 100) / 100).toFixed(2);
      });
    },
  },
  created() {
    if (screenfull.enabled) {
      screenfull.on('change', this.screenChangehandler);
    }
    this.getSubaccountAsset();
    this.paymentInfo();
    this.activeWorkerList();
    this.inActiveWorkerList();
    this.subaccountStats();
    this.timer = setInterval(() => {
      this.subaccountStats();
      this.paymentInfo();
      this.subaccountHistory();
      this.getHistoryProfit();
      this.activeWorkerList();
      this.inActiveWorkerList();
      this.getWorkerStas();
    }, 15000);
  },
  beforeDestroy() {
    this.isFullscreen = false;
    this.exitFullScreen();
    screenfull.off('change', this.screenChangehandler);
    clearInterval(this.timer);
  },
  methods: {
    ...mapMutations(['SET_IS_FULLSCREEN']),
    toggleEchartsLang() {
      this.kuangJiEchartsOption.legend.data = [this.$t('dashboard.active_minging_mashine_number'), this.$t('dashboard.mining_machine_assets')];
      this.kuangJiEchartsOption.yAxis[0].name = this.$t('dashboard.machine_number');
      this.kuangJiEchartsOption.series[0].name = this.$t('dashboard.active_minging_mashine_number');
      this.kuangJiEchartsOption.series[1].name = this.$t('dashboard.mining_machine_assets');

      if (this.$refs.kuangji_noFull_echarts) {
        this.$refs.kuangji_noFull_echarts.setOption(this.kuangJiEchartsOption);
      }

      this.kuangJiFullEchartsOption.legend.data = [this.$t('dashboard.active_minging_mashine_number'), this.$t('dashboard.mining_machine_assets')];
      this.kuangJiFullEchartsOption.yAxis[0].name = this.$t('dashboard.machine_number');
      this.kuangJiFullEchartsOption.series[0].name = this.$t('dashboard.active_minging_mashine_number');
      this.kuangJiFullEchartsOption.series[1].name = this.$t('dashboard.mining_machine_assets');

      if (this.$refs.kuangji_full_echarts) {
        this.$refs.kuangji_full_echarts.setOption(this.kuangJiFullEchartsOption);
      }

      this.shouyiOption.legend.data = [this.$t('dashboard.income')];
      this.shouyiOption.yAxis.name = this.$t('dashboard.income');
      this.shouyiOption.series[0].name = this.$t('dashboard.income');

      if (this.$refs['shouyi-echarts']) {
        this.$refs['shouyi-echarts'].setOption(this.shouyiOption);
      }

      this.suanLiEchartsOption.legend.data = [this.$t('dashboard.rate'), this.$t('dashboard.hash_rate'), this.$t('dashboard.refuse_rate')];
      this.suanLiEchartsOption.yAxis[0].name = this.$t('dashboard.rate');
      this.suanLiEchartsOption.yAxis[1].name = this.$t('dashboard.refuse_rate');
      this.suanLiEchartsOption.series[0].name = this.$t('dashboard.rate');
      this.suanLiEchartsOption.series[1].name = this.$t('dashboard.hash_rate');
      this.suanLiEchartsOption.series[2].name = this.$t('dashboard.refuse_rate');

      if (this.$refs.suanli_noFull_echarts) {
        this.$refs.suanli_noFull_echarts.setOption(this.suanLiEchartsOption);
      }

      this.suanLiFullEchartsOption.legend.data = [this.$t('dashboard.rate'), this.$t('dashboard.hash_rate'), this.$t('dashboard.refuse_rate')];
      this.suanLiFullEchartsOption.yAxis[0].name = this.$t('dashboard.rate');
      this.suanLiFullEchartsOption.yAxis[1].name = this.$t('dashboard.refuse_rate');
      this.suanLiFullEchartsOption.series[0].name = this.$t('dashboard.rate');
      this.suanLiFullEchartsOption.series[1].name = this.$t('dashboard.hash_rate');
      this.suanLiFullEchartsOption.series[2].name = this.$t('dashboard.refuse_rate');

      if (this.$refs.suanli_full_echarts) {
        this.$refs.suanli_full_echarts.setOption(this.suanLiFullEchartsOption);
      }
    },
    toSetWarning() {
      this.$router.push('/subaccount?type=setwarning');
    },
    getWarning() {
      // 有15m算力，且没有算力预警
      if (!this.getWarning_init) {
        return;
      }
      this.getWarning_init = false;
      getWarning({ cuid: this.subCuid }).then((res) => {
        if (res.data.status === 1 && !res.data.data) {
          this.showWarningInfo = true;
        }
        this.getWarning_init = false;
      }).catch(() => {
        this.getWarning_init = true;
      });
    },
    setSubaccountAsset(type) {
      // type:1 矿机资产 2算力
      const params = {
        type,
        cuid: this.subCuid,
        uid: this.id,
      };
      if (type === 1) {
        if (this.loading.set_subaccount_asset_worker_loading) {
          return;
        }
        Object.assign(params, { worker_num: this.set_asset.worker_num });
        this.loading.set_subaccount_asset_worker_loading = true;
      } else {
        if (this.loading.set_subaccount_asset_share_loading) {
          return;
        }
        Object.assign(params, {
          share: this.set_asset.hash_rate,
          unit: this.set_asset.unit,
        });
        this.loading.set_subaccount_asset_share_loading = true;
      }
      setSubaccountAsset(params).then((res) => {
        if (res.data.status === 1) {
          this.$notify({
            message: type === 1 ? this.$t('dashboard.set_mining') : this.$t('dashboard.set_hash_rate_success'),
            type: 'success',
            duration: 1000,
            showClose: false,
          });
          if (type === 1) {
            this.asset.worker_num = params.worker_num;
            this.kuangji_is_setting = false;
          } else {
            this.asset.unit = params.unit;
            this.asset.share = params.share;
            this.suanli_is_setting = false;
          }
        }
        this.loading.set_subaccount_asset_share_loading = false;
        this.loading.set_subaccount_asset_worker_loading = false;
      }).catch(() => {
        this.loading.set_subaccount_asset_share_loading = false;
        this.loading.set_subaccount_asset_worker_loading = false;
      });
    },
    getSubaccountAsset() {
      this.loading.get_subaccount_asset_loading = true;
      getSubaccountAsset({
        puid: this.subCuid,
      }).then((res) => {
        if (res.data.status === 1) {
          const data = res.data.data;
          if (Array.isArray(data) && !data.length) {
            [this.asset] = [{
              unit: 'T',
              share: 0,
              worker_num: 0,
            }];
          } else {
            [this.asset] = [data];
          }
        }
        this.loading.get_subaccount_asset_loading = false;
      }).catch(() => {
        this.loading.get_subaccount_asset_loading = false;
      });
    },
    getWorkerStas() {
      if (this.loading.getWorkerStas_loading) {
        return;
      }
      this.loading.getWorkerStas_loading = true;
      getWorkerStas({ cuid: this.subCuid, type: this.kuangji_dimension }).then((res) => {
        if (res.data.status === 1) {
          this.get_worker_stas_data = res.data.data;
          this.setKuangJiEchartsOption('kuangJiEchartsOption', 'kuangji_noFull_echarts');
          this.setKuangJiEchartsOption('kuangJiFullEchartsOption', 'kuangji_full_echarts');
        }
        this.loading.getWorkerStas_init_loading = false;
        this.loading.getWorkerStas_loading = false;
      }).catch(() => {
        this.loading.getWorkerStas_init_loading = false;
        this.loading.getWorkerStas_loading = false;
      });
    },
    setKuangJiEchartsOption(optionName, echartsName) {
      this[optionName].xAxis.data = this.get_worker_stas_data.time;
      this[optionName].series[0].data = this.get_worker_stas_data.active;
      this[optionName].series[1].data = this.get_worker_stas_data.inactive;
      this[optionName].tooltip.formatter = (v) => {
        let str = '';
        v.filter(item => item.axisDim === 'x').forEach((item, index) => {
          if (!index) {
            str += `${this.$t('dashboard.time')}：${item.axisValue}`;
          }
          if (item.color === '#70c1b3') {
            str += `<br/><i style="background:${item.color};display:inline-block;height:12px;width:12px;border-radius:6px;"></i> ${this.$t('dashboard.active_minging_mashine_number')}：${item.data}`;
          }
          if (item.color === '#ccc') {
            str += `<br/><i style="background:${item.color};display:inline-block;height:12px;width:12px;border-radius:6px;"></i> ${this.$t('dashboard.mining_machine_assets')}：${item.data}`;
          }
        });
        return str;
      };
      this[optionName].xAxis.axisLabel.formatter = (v) => {
        const arr = v.split(' ');
        return arr[1] ? `${arr[1]}\n${arr[0]}` : arr[0];
      };
      if (this.$refs[echartsName]) {
        this.$refs[echartsName].setOption(this[optionName]);
      }
    },
    subaccountHistory() {
      if (this.loading.subaccountHistory_loading) {
        return;
      }
      this.loading.subaccountHistory_loading = true;
      const count = this.suanLi_dimension === '1h' ? 48 : 30;
      subaccountHistory({
        puid: this.subCuid,
        dimension: this.suanLi_dimension,
        count,
      }).then((res) => {
        if (res.data.status === 1) {
          const time = [];
          const unit = res.data.unit;
          const shareAccept = [];
          const rejectRate = [];
          res.data.data.forEach((v) => {
            time.push(v.time);
            shareAccept.push(v.share);
            rejectRate.push((v.reject * 100).toFixed(2));
          });
          this.subaccount_history_time = time;
          this.subaccount_history_share = shareAccept;
          this.subaccount_history_rejectRate = rejectRate;
          this.subaccount_history_unit = unit;
          this.setSuanliEchartsOption('suanLiEchartsOption', 'suanli_noFull_echarts');
          this.setSuanliEchartsOption('suanLiFullEchartsOption', 'suanli_full_echarts');
        }
        this.loading.subaccountHistory_init_loading = false;
        this.loading.subaccountHistory_loading = false;
      }).catch(() => {
        this.loading.subaccountHistory_init_loading = false;
        this.loading.subaccountHistory_loading = false;
      });
    },
    setSuanliEchartsOption(optionName, echartsName) {
      this[optionName].xAxis.data = this.subaccount_history_time;
      this[optionName].yAxis[0].name = `${this.$t('dashboard.rate')}(${this.asset.unit}H/S)`;
      this[optionName].yAxis[1].name = `${this.$t('dashboard.refuse_rate')}(%)`;
      this[optionName].series[0].data = this.subaccount_history_current_share;
      this[optionName].series[1].data = new Array(this.subaccount_history_current_share.length).fill(this.asset.share);
      this[optionName].series[2].data = this.subaccount_history_rejectRate;
      this[optionName].tooltip.formatter = (v) => {
        let str = '';
        v.filter(item => item.axisDim === 'x').forEach((item, index) => {
          if (!index) {
            str = `${this.$t('dashboard.time')}：${moment(item.axisValue * 1000).format(this.suanLi_dimension === '1h' ? 'YYYY-MM-DD HH:mm' : 'YYYY-MM-DD')}`;
          }
          if (item.color === '#70c1b3') {
            str += `<br/><i style="background:${item.color};display:inline-block;height:12px;width:12px;border-radius:6px;"></i> ${this.$t('dashboard.rate')}：${item.data}(${this.asset.unit}H/S)`;
          }
          if (item.color === '#ccc') {
            str += `<br/><i style="background:${item.color};display:inline-block;height:12px;width:12px;border-radius:6px;"></i> ${this.$t('dashboard.hash_rate')}：${item.data}(${this.asset.unit}H/S)`;
          }
          if (item.color === '#eb547c') {
            str += `<br/><i style="background:${item.color};display:inline-block;height:12px;width:12px;border-radius:6px;"></i> ${this.$t('dashboard.refuse_rate')}：${item.data}%`;
          }
        });
        return str;
      };
      this[optionName].xAxis.axisLabel.formatter = (value) => {
        const formatterTime = moment(value * 1000).format(
          this.suanLi_dimension === '1h' ? 'HH:mm YYYY-MM-DD' : 'YYYY-MM-DD',
        );
        return formatterTime.split(' ').join('\n');
      };
      if (this.$refs[echartsName]) {
        this.$refs[echartsName].setOption(this[optionName]);
      }
    },
    subaccountStats() {
      if (this.loading.subaccountStats_loading) {
        return;
      }
      this.loading.subaccountStats_loading = true;
      subaccountStats({
        puid: this.subCuid,
      }).then((res) => {
        if (res.data.status === 1) {
          const data = res.data.data;
          this.shares_15m = data.shares_15m;
          // 有15m算力，且没有算力预警
          if (Number(this.shares_15m)) {
            this.getWarning();
          }
          this.shares_1h = data.shares_1h;
          this.shares_24h = data.shares_24h;
          this.shares_unit = data.shares_unit;
          this.workers_active = data.workers_active;
          this.workers_dead = data.workers_dead;
          this.workers_inactive = data.workers_inactive;
          this.noMill = (data.workers_active + data.workers_inactive + data.workers_dead) === 0;
        }
        this.loading.subaccountStats_init_loading = false;
        this.loading.subaccountStats_loading = false;
      }).catch(() => {
        this.loading.subaccountStats_init_loading = false;
        this.loading.subaccountStats_loading = false;
      });
    },
    inActiveWorkerList() {
      if (this.loading.inActive_workers_loading) {
        return;
      }
      this.loading.inActive_workers_loading = true;
      workerList({
        puid: this.subCuid,
        page: 1,
        pagesize: 6,
        status: 'INACTIVE',
        order_by: 'last_share_time',
        sort: 'desc',
      }).then((res) => {
        if (res.data.status === 1) {
          this.inActive_workers = res.data.data.list;
        }
        this.loading.inActive_workers_loading = false;
      }).catch(() => {
        this.loading.inActive_workers_loading = false;
      });
    },
    activeWorkerList() {
      if (this.loading.active_workers_loading) {
        return;
      }
      this.loading.active_workers_loading = true;
      workerList({
        puid: this.subCuid,
        page: 1,
        pagesize: 6,
        status: 'ACTIVE',
        order_by: 'shares_15m',
        sort: 'asc',
      }).then((res) => {
        if (res.data.status === 1) {
          this.active_workers = res.data.data.list;
        }
        this.loading.active_workers_loading = false;
      }).catch(() => {
        this.loading.active_workers_loading = false;
      });
    },
    paymentInfo() {
      if (this.loading.paymentInfo_loading) {
        return;
      }
      this.loading.paymentInfo_loading = true;
      paymentInfo({ puid: this.subCuid }).then((res) => {
        if (res.data.status === 1) {
          const data = res.data.data;
          Object.assign(this.paymentInfoData, {
            earn: parseFloat(data.earn).toFixed(8),
            pay_amount: parseFloat(data.pay_amount).toFixed(8),
            per: parseFloat(data.per).toFixed(8),
            total_earn: parseFloat(data.total_earn).toFixed(8),
            yesterdayearn: parseFloat(data.yesterdayearn).toFixed(8),
          });
        }
        this.loading.paymentInfo_init_loading = false;
        this.loading.paymentInfo_loading = false;
      }).catch(() => {
        this.loading.paymentInfo_init_loading = false;
        this.loading.paymentInfo_loading = false;
      });
    },
    getHistoryProfit() {
      if (this.loading.paymentHistory_loading) {
        return;
      }
      this.loading.paymentHistory_loading = true;
      getHistoryProfit({
        puid: this.subCuid,
        pagesize: this.paymentHistoryLimit,
        page: 1,
        orderBy: 'day',
        sort: 'desc',
      }).then((res) => {
        if (res.data.status === 1) {
          const list = res.data.data.list;
          const xData = [];
          const seriesData = [];
          list.reverse().forEach((v) => {
            xData.push(v.day);
            seriesData.push(v.total_rewards / (10 ** 8));
          });

          this.shouyiOption.xAxis.data = xData;
          this.shouyiOption.series[0].data = seriesData;
          this.shouyiOption.tooltip.formatter = (v) => {
            const arr = v.filter(item => item.axisDim === 'x');
            return `${this.$t('dashboard.time')}：${arr[0].name}<br/>${this.$t('dashboard.income')}：${arr[0].value} BTC`;
          };
          this.$refs['shouyi-echarts'].setOption(this.shouyiOption);
        }
        this.loading.paymentHistory_loading = false;
        this.loading.paymentHistory_init_loading = false;
      }).catch(() => {
        this.loading.paymentHistory_loading = false;
        this.loading.paymentHistory_init_loading = false;
      });
    },
    closeSetting() {
      if (!this.loading.set_subaccount_asset_worker_loading) {
        this.kuangji_is_setting = false;
      }
      if (!this.loading.set_subaccount_asset_share_loading) {
        this.suanli_is_setting = false;
      }
    },
    toFullScreen() {
      if (screenfull.enabled) {
        screenfull.request();
      } else {
        // 不支持全屏
        this.$message.error(this.$t('dashboard.no_support'));
      }
    },
    exitFullScreen() {
      if (screenfull.enabled) {
        screenfull.exit();
      }
    },
    screenChangehandler() {
      this.isFullscreen = screenfull.isFullscreen;
      if (this.isFullscreen) {
        this.$refs.suanli_full_echarts.chart.resize({
          height: 2.239583 * window.rem,
          width: 4.453125 * window.rem,
        });
        this.$refs.kuangji_full_echarts.chart.resize({
          height: 2.239583 * window.rem,
          width: 4.453125 * window.rem,
        });
      }
    },
  },
  watch: {
    'set_asset.hash_rate': {
      handler(val) {
        let v = val.toString();
        v = v.replace(/[^\d.]/g, '');
        if (v < 0) {
          v = '0';
        }
        if (v > 10000) {
          v = '10000';
        }
        let arr = v.split('.');
        if (arr.length > 2) {
          v = `${arr[0]}.${arr[1]}`;
          arr = v.split('.');
        }
        if (arr[1] && arr[1].length > 2) {
          v = `${arr[0]}.${arr[1][0]}${arr[1][1]}`;
        }
        this.set_asset.hash_rate = v;
      },
    },
    'set_asset.worker_num': {
      handler(val) {
        let v = val.toString();
        v = v.replace(/[^\d]/g, '');
        if (v < 0) {
          v = '0';
        }
        if (v > 200000) {
          v = '200000';
        }
        this.set_asset.worker_num = v;
      },
    },
    'asset.unit': {
      handler() {
        this.setSuanliEchartsOption('suanLiEchartsOption', 'suanli_noFull_echarts');
        this.setSuanliEchartsOption('suanLiFullEchartsOption', 'suanli_full_echarts');
      },
    },
    'asset.share': {
      handler() {
        this.setSuanliEchartsOption('suanLiEchartsOption', 'suanli_noFull_echarts');
        this.setSuanliEchartsOption('suanLiFullEchartsOption', 'suanli_full_echarts');
      },
    },
    'asset.worker_num': {
      handler() {
        this.getWorkerStas();
      },
    },
    subCuid() {
      // 矿机资产  理论算力
      this.getSubaccountAsset();
      this.loading.subaccountStats_init_loading = true;
      // 获取算力预警
      this.showWarningInfo = false;
      this.getWarning_init = true;
      // 实时算力
      this.subaccountStats();
      this.loading.paymentInfo_init_loading = true;
      // 收益信息
      this.paymentInfo();
      this.loading.subaccountHistory_init_loading = true;
      // 算力图
      this.subaccountHistory();
      this.loading.paymentHistory_init_loading = true;
      // 收益图
      this.getHistoryProfit();
      this.loading.getWorkerStas_init_loading = true;
      // 矿机图
      this.getWorkerStas();

      this.activeWorkerList();
      this.inActiveWorkerList();
    },
    paymentHistoryLimit: {
      handler() {
        this.getHistoryProfit();
      },
      immediate: true,
    },
    suanLi_dimension: {
      handler() {
        this.subaccountHistory();
      },
      immediate: true,
    },
    kuangji_dimension: {
      handler() {
        this.getWorkerStas();
      },
      immediate: true,
    },
    language: {
      handler() {
        this.toggleEchartsLang();
      },
      immediate: true,
    },
  },
};
</script>
